package fr.orleans.publique;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import entities.Event;
import entities.Match;
import entities.PlayerEvent;
import fr.orleans.tools.JSFServices;
import fr.orleans.tools.ManagedBeans;

@ManagedBean
@ViewScoped
public class MatchDetail extends ManagedBeans{

	private Match oneMatch;
	private List<PlayerEvent> listPlayerEvent;
	
	public MatchDetail(){
		try{
			this.setOneMatch((Match) JSFServices.getParameterInRequestMap("match"));
		}catch(Exception e){
			
		}
	}

	public Match getOneMatch() {
		if(this.oneMatch == null)
			this.oneMatch = (Match) JSFServices.getParameterInRequestMap("match");
		return oneMatch;
	}

	public void setOneMatch(Match oneMatch) {
		this.oneMatch = oneMatch;
	}

	public List<PlayerEvent> getListPlayerEvent() {
		List<Event> listTmp = new ArrayList<>(this.oneMatch.getListEvent());
		
		this.listPlayerEvent = new ArrayList<PlayerEvent>();
		
		for(Event event : listTmp){
			if(event.getClass().equals(PlayerEvent.class)){
				PlayerEvent playerE = (PlayerEvent) event;
				this.listPlayerEvent.add(playerE);
				System.out.println("Player : " + playerE.getPlayer().toString());
				System.out.println("Type : " + playerE.getTypeEventPlayer().toString());
			}
		}
				
		return listPlayerEvent;
	}

	public void setListPlayerEvent(List<PlayerEvent> listPlayerEvent) {
		this.listPlayerEvent = listPlayerEvent;
	}
	
	public String goToBackDetailTournament(){
		JSFServices.putParameterInRequestMap("tournament", this.oneMatch.getTournament());
		return "/modules/public/detailTournament.jsf";
	}
}